package com.xixilala.controllers.login;

import com.xixilala.po.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    private final Logger logger = LoggerFactory.getLogger(LoginController.class);

    @GetMapping(value = "/admin/login")
    public String login(ModelMap modelMap, HttpSession session) {

        modelMap.put("message", "testmsg");

        User user = new User();
        user.setUsername("testname");
        user.setPassword("testpassword");
        
        session.setAttribute("user", user);
        return "admin/login";
    }

    @PostMapping(value = "/login")
    public String toLogin(HttpServletRequest request,
                          HttpServletResponse response,
                          @RequestParam String username,
                          @RequestParam String password) {
        logger.debug("username={},password={}",username,password);



        return "success";
    }
}
